package com.yinhe.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.domain.SysApplicationsRoles;
import com.yinhe.system.service.ISysApplicationsRolesService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 角色应用关联Controller
 * 
 * @author yinhe
 * @date 2022-07-21
 */
@RestController
@RequestMapping("/system/roles")
public class SysApplicationsRolesController extends BaseController
{
    @Autowired
    private ISysApplicationsRolesService sysApplicationsRolesService;

    /**
     * 查询角色应用关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:roles:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysApplicationsRoles sysApplicationsRoles)
    {
        startPage();
        List<SysApplicationsRoles> list = sysApplicationsRolesService.selectSysApplicationsRolesList(sysApplicationsRoles);
        return getDataTable(list);
    }

    /**
     * 导出角色应用关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:roles:export')")
    @Log(title = "角色应用关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysApplicationsRoles sysApplicationsRoles)
    {
        List<SysApplicationsRoles> list = sysApplicationsRolesService.selectSysApplicationsRolesList(sysApplicationsRoles);
        ExcelUtil<SysApplicationsRoles> util = new ExcelUtil<SysApplicationsRoles>(SysApplicationsRoles.class);
        util.exportExcel(response, list, "角色应用关联数据");
    }

    /**
     * 获取角色应用关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:roles:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId)
    {
        return AjaxResult.success(sysApplicationsRolesService.selectSysApplicationsRolesByRoleId(roleId));
    }

    /**
     * 新增角色应用关联
     */
    @PreAuthorize("@ss.hasPermi('system:roles:add')")
    @Log(title = "角色应用关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysApplicationsRoles sysApplicationsRoles)
    {
        return toAjax(sysApplicationsRolesService.insertSysApplicationsRoles(sysApplicationsRoles));
    }

    /**
     * 修改角色应用关联
     */
    @PreAuthorize("@ss.hasPermi('system:roles:edit')")
    @Log(title = "角色应用关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysApplicationsRoles sysApplicationsRoles)
    {
        return toAjax(sysApplicationsRolesService.updateSysApplicationsRoles(sysApplicationsRoles));
    }

    /**
     * 删除角色应用关联
     */
    @PreAuthorize("@ss.hasPermi('system:roles:remove')")
    @Log(title = "角色应用关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds)
    {
        return toAjax(sysApplicationsRolesService.deleteSysApplicationsRolesByRoleIds(roleIds));
    }
}
